package com.wangjiang.mario.admin.web.admin.controller.v1;

import com.wangjiang.mario.admin.common.base.BaseController;
import com.wangjiang.mario.admin.common.object.UUidList;
import com.wangjiang.mario.admin.common.object.UUidListForBatchUpdate;
import com.wangjiang.mario.admin.common.rest.ResultGenerator;
import com.wangjiang.mario.admin.common.rest.entity.Result;
import com.wangjiang.mario.admin.system.domain.components.ConfigComponent;
import com.wangjiang.mario.admin.system.domain.entity.LogEntity;
import com.wangjiang.mario.admin.system.domain.service.LogService;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * 日志控制器
 *
 * @author wangjiang
 * @datetime 2019-10-17 16:52:49
 */

@RestController
@RequestMapping("/log")
@Api(value = "/log", tags = "日志控制器")
public class LogController extends BaseController<LogEntity> {

    private static final Logger logger = LoggerFactory.getLogger(LogController.class);

    @Autowired
    private ConfigComponent configComponent;

    @Autowired
    private LogService logService;

    @GetMapping("")
    public Result list (
            LogEntity qo,
            @RequestParam(name = "currentPage", defaultValue = "1") Integer currentPage,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        return ResultGenerator.genSuccessResult(baseService.basePage(currentPage, pageSize, qo, LogEntity.class));
    }

    /**
     * 根据uuid 获取实体信息
     *
     * @param uuid
     * @return
     */
    @GetMapping("/{uuid}")
    public Result getOne (@PathVariable String uuid) {
        return ResultGenerator.genSuccessResult(baseService.baseGetByUUid(uuid, LogEntity.class));
    }

    @GetMapping("/all")
    public Result all (LogEntity qo) throws IllegalAccessException {
        return ResultGenerator.genSuccessResult(baseService.list(qo));
    }

    @PostMapping("")
    public Result create (@RequestBody LogEntity entity) {
        return ResultGenerator.genSuccessResult(baseService.baseSave(entity));
    }

    @PutMapping("")
    public Result update(@RequestBody LogEntity entity) {
        return ResultGenerator.genSuccessResult(baseService.baseUpdateById(entity));
    }

    @PutMapping("/batch")
    public Result batchUpdate(
            @RequestBody UUidListForBatchUpdate<LogEntity> uuidListForBatchUpdate
    ) {
        return ResultGenerator.genSuccessResult(baseService.baseUpdateBatch(uuidListForBatchUpdate));
    }

    @DeleteMapping("")
    public Result delete(
            @RequestParam String uuid
    ) {
        return ResultGenerator.genSuccessResult(baseService.baseSoftRemoveById(uuid));
    }

    @DeleteMapping("/batch")
    public Result batchDelete(
            @RequestBody UUidList uuidList
    ) {
        return ResultGenerator.genSuccessResult(baseService.baseBatchSoftRemoveByUUidList(uuidList));
    }
}
